package gui.visu.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.Timer;

import controls.DataControl;
import data.Constants;


/**
 * @author Charles Perin
 * 29 mars 2011
 * LIMSI - INRIA Rennes
 * charles.perin@free.fr
 *
 */
public class ListenerGoButton extends MouseAdapter{

	private DataControl dataControl;

	private Timer repeatTimer;
	private boolean move;
	
	public ListenerGoButton(DataControl dataControl, boolean move){
		setDataControl(dataControl);
		setMove(move);
	}

	public void mousePressed(MouseEvent arg0)
	{
		dataControl.getDisplayDataList().moveDisplayDataXView(move);
		dataControl.updateVisuPane();
		

		repeatTimer = new Timer(Constants.BUTTON_TIMER_DELAY, new ActionListener() {
			public void actionPerformed(ActionEvent e){
				dataControl.getDisplayDataList().moveDisplayDataXView(move);
				dataControl.updateVisuPane();
			}
		});
		repeatTimer.setInitialDelay(500);
		repeatTimer.start();
	}
	public void mouseReleased(MouseEvent arg0){
		repeatTimer.stop();
	}

	public DataControl getDataControl() {
		return dataControl;
	}

	public void setDataControl(DataControl dataControl) {
		this.dataControl = dataControl;
	}

	public void setMove(boolean move) {
		this.move = move;
	}

	public boolean isMove() {
		return move;
	}
}
